<?php
/*
 * This is success page from paypal payment.
 */
include '../include/config.php';

session_start();
$user_name = $_SESSION['user_name'];
$sur_name = $_SESSION['sur_name'];
$password = $_SESSION['password'];
$email = $_SESSION['email'];
$key = '360technosoft';

function _encode($password, $key) {
    $majorsalt = null;
    if ($key != '') {
        $_password = $key . $password;
    } else {
        $_password = $password;
    }
    if (function_exists('str_split')) {
        $_pass = str_split($_password);
    } else {
        $_pass = array();
        if (is_string($_password)) {
            for ($i = 0; $i < strlen($_password); $i++) {
                array_push($_pass, $_password[$i]);
            }
        }
    }

    foreach ($_pass as $_hashpass) {
        $majorsalt .= md5($_hashpass);
    }
    return $password = md5($majorsalt);
}

$pad = $_SESSION['amount'];
//$item_currency = $_GET['cc'];
?>


Welcome, <b><?= $user_name ?></b><br/>
Payment successful...!!!<br/><br/><br/>

Now, please wait, while we are configuring your profile....
<?php
/*
 * inserting data to main user table.
 * just modify user_name = $username-->with $email.
 * 
 */
$password = _encode($password, $key);
mysql_query("insert into fa_user(`id`,`user_name`,`password`,`email`,`role`,`sur_name`) values(NULL,'" . $user_name . "', '" . $password . "','" . $email . "','user','" . $sur_name . "' )") or die(mysql_error());
echo 'Done<br>';
$uid = mysql_insert_id();
echo $uid;
/*
 * inserting data into buy_products.
 */
mysql_query("insert into salus_buy_product(`id`,`FK_fa_user_id`,`FK_fa_product_id`,`product_prize`,`date`) values(NULL,'" . $uid . "',2,'" . $pad . "','" . date('Y-m-d') . "') ") or die(mysql_error());
echo 'Done<br>';

/*
 * inserting into child profile database
 */
if ($_SESSION['gender'] == 'M') {
    $idd = 'father_id';
} else {
    $idd = 'mother_id';
}
mysql_query("insert into baby_child_profile_detail (bid,buyer_id," . $idd . ") values(NULL,'" . $uid . "','" . $uid . "') ") or die(mysql_error());
echo 'Done<br>';
/*
 * inserting into user_profile
 */
mysql_query("insert into salus_user_profile_detail (id,FK_fa_user_id,name,sur_name,sex,email) value(NULL,'" . $uid . "','" . $user_name . "','" . $sur_name . "','" . $_SESSION['gender'] . "','" . $email . "') ") or die(mysql_error());
echo 'Done<br>';

echo 'Account created successfully. goto <a href="http://' . $_SERVER['HTTP_HOST'] . '/salusbaby"> home page</a> for login to your profile.';
?>
